-
-
Notifications
You must be signed in to change notification settings - Fork 705
Fix fragile doctest sorting in multi_polynomial_ideal #41206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Hapsa21
wants to merge
2
commits into
sagemath:develop
Choose a base branch
from
Hapsa21:fix-issue-41193
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…t insertion order
Contributor
|
Thank you. LGTM |
vbraun
pushed a commit
to vbraun/sage
that referenced
this pull request
Nov 21, 2025
sagemathgh-41206: Fix fragile doctest sorting in multi_polynomial_ideal ### Description This PR fixes a fragile doctest failure reported in sagemath#41193. **The Issue:** The failing test in `src/sage/rings/polynomial/multi_polynomial_ideal.py` used `sorted(..., key=str)` on a list of dictionaries. In Python, the string representation of a dictionary depends on the insertion order of its keys. Since the upstream library `msolve` likely changed its internal insertion order in newer versions, `key=str` produced a different sort order than expected, causing the test to fail despite the mathematical results being correct. **The Fix:** I updated the test command to replace the unstable sort key with a robust one. This sorts the dictionary items before stringifying, ensuring the sorting relies on the dictionary *contents* rather than their internal memory layout. ```python # Old (fragile) key=str # New (robust) key=lambda d: str(sorted(d.items())) ``` **Verification** I verified that this change makes the sorting immune to dictionary insertion order. **Proof of Fix**: Running the following script demonstrates why `key=str` failed and why the new key succeeds: ```python dict_A = {'x': 100, 'y': 500} dict_B = {'y': 500, 'x': 100} # ---Old Behavior (key=str)--- # str(dict_A) is "{'x': 100, 'y': 500}" # str(dict_B) is "{'y': 500, 'x': 100}" print(f"Old method equal? {str(dict_A) == str(dict_B)}") # Result: False (This caused the test failure) # --- New Behavior (The Fix) --- my_key = lambda d: str(sorted(d.items())) print(f"New method equal? {my_key(dict_A) == my_key(dict_B)}") # Result: True (The sort is now stable) ``` This ensures the doctest passes reliably regardless of the upstream library's behavior. ### **Issue** Fixes sagemath#41193 Relates to sagemath#41192 ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies None. URL: sagemath#41206 Reported by: Hetarth Jodha Reviewer(s):
Contributor
|
There are 14 similar failures in |
vbraun
pushed a commit
to vbraun/sage
that referenced
this pull request
Nov 26, 2025
sagemathgh-41206: Fix fragile doctest sorting in multi_polynomial_ideal ### Description This PR fixes a fragile doctest failure reported in sagemath#41193. **The Issue:** The failing test in `src/sage/rings/polynomial/multi_polynomial_ideal.py` used `sorted(..., key=str)` on a list of dictionaries. In Python, the string representation of a dictionary depends on the insertion order of its keys. Since the upstream library `msolve` likely changed its internal insertion order in newer versions, `key=str` produced a different sort order than expected, causing the test to fail despite the mathematical results being correct. **The Fix:** I updated the test command to replace the unstable sort key with a robust one. This sorts the dictionary items before stringifying, ensuring the sorting relies on the dictionary *contents* rather than their internal memory layout. ```python # Old (fragile) key=str # New (robust) key=lambda d: str(sorted(d.items())) ``` **Verification** I verified that this change makes the sorting immune to dictionary insertion order. **Proof of Fix**: Running the following script demonstrates why `key=str` failed and why the new key succeeds: ```python dict_A = {'x': 100, 'y': 500} dict_B = {'y': 500, 'x': 100} # ---Old Behavior (key=str)--- # str(dict_A) is "{'x': 100, 'y': 500}" # str(dict_B) is "{'y': 500, 'x': 100}" print(f"Old method equal? {str(dict_A) == str(dict_B)}") # Result: False (This caused the test failure) # --- New Behavior (The Fix) --- my_key = lambda d: str(sorted(d.items())) print(f"New method equal? {my_key(dict_A) == my_key(dict_B)}") # Result: True (The sort is now stable) ``` This ensures the doctest passes reliably regardless of the upstream library's behavior. ### **Issue** Fixes sagemath#41193 Relates to sagemath#41192 ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies None. URL: sagemath#41206 Reported by: Hetarth Jodha Reviewer(s):
Contributor
Author
i've fixed it |
Contributor
|
Wait CI agree this. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a fragile doctest failure reported in #41193.
The Issue:
The failing test in
src/sage/rings/polynomial/multi_polynomial_ideal.pyusedsorted(..., key=str)on a list of dictionaries. In Python, the string representation of a dictionary depends on the insertion order of its keys. Since the upstream librarymsolvelikely changed its internal insertion order in newer versions,key=strproduced a different sort order than expected, causing the test to fail despite the mathematical results being correct.The Fix:
I updated the test command to replace the unstable sort key with a robust one. This sorts the dictionary items before stringifying, ensuring the sorting relies on the dictionary contents rather than their internal memory layout.
Verification
I verified that this change makes the sorting immune to dictionary insertion order.
Proof of Fix: Running the following script demonstrates why
key=strfailed and why the new key succeeds:This ensures the doctest passes reliably regardless of the upstream library's behavior.
Issue
Fixes #41193 Relates to #41192
📝 Checklist
⌛ Dependencies
None.